package wh.什么是ACM;

import com.sun.deploy.util.StringUtils;
import wh.实现strStr函数.Str;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2022/12/21 11:04
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        String S = "BBQELECTRONICABCSPORTSFFT";
        String T = "PPPACMACMACMCBDEMACCAMTTT";
        char[] charS = S.toCharArray();
        char[] charT = T.toCharArray();
        List<String> list = new ArrayList<>();
        Boolean bool = false;
        for (int i = 0; i < charT.length; i++) {
            if (charT[i] == 'A' || charT[i] == 'C' || charT[i] == 'M'){
                bool = true;
             list.add(String.valueOf(charS[i]));
            }else {
                if (list.size() != 0 && bool == true){
                    list.add(" ");
                    bool = false;
                }
            }
        }
        if (list.get(list.size() - 1) == " "){
            list.remove(list.size() - 1);
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            stringBuilder.append(list.get(i));
        }
        String substring = stringBuilder.substring(0, stringBuilder.length());
        System.out.println(substring);

    }

}
